<?php

namespace Admin\Controller;

use Common\Controller\AdminController;

class UserController extends AdminController {

    public function index() {
        $userModel = new \Admin\Model\UserModel();
        $where = array();
        $user = $userModel->getList($where, $param);
        $this->user = $user['list'];
        $this->page = $user['page'];
        if(IS_AJAX){
            $this->ajaxReturn($this->fetch('User/index_ajax'));
        }
        $this->display();
    }

    public function downUser() {
        $userModel = new \Admin\Model\UserModel();
        $where = array();
        $user = $userModel->getListForExcel($where, $param);
        $next_table = "<table border='1' style='text-align:center;width: 50%;margin: 0 auto;'> <tr>
                                    <th>编号</th>
                                    <th>用户名</th>
                                    <th>手机号</th>
                                    <th>注册时间</th>
                                </tr>";
        foreach ($user['list'] as $key => $value) {
            $one = "<tr>";
            $one .= "<td>" . ($key + 1) . "</td>";
            $one .= "<td>" . $value['name'] . "</td>";
            $one .= "<td>" . $value['tel'] . "</td>";
            $one .= "<td>" . $value['createdt'] . "</td>";
            $one .= "</tr>";
            $next_table.=$one;
        }
        $next_table.="</table>";
        $filename = '用户信息';
        header("Content-type:application/octet-stream;charset=utf-8");
        header("Accept-Ranges:bytes");
        header("Content-type:application/vnd.ms-excel");
        header("Content-Disposition:attachment;filename=" . $filename . ".xls");
        header("Pragma: no-cache");
        header("Expires: 0");
        ob_start();
        echo $next_table;
        ob_flush();
        exit;
    }

}
